﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using aier.business.logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using aier.dataaccess.dapper;
using aier.xrm.wcf;
using aier.dataaccess.model;
using log4net;

namespace aier.business.logic
{
    [TestClass()]
    public class CommonBllUT
    {
        private CommonBll commonBll = null;
        private LeadBll leadBll = null;
        private ScreenCustomerBll screenCustomerBll = null;
        private ScreenResultBll screenResultBll = null;
        private ScreenPropagandaBll screenPropagandaBll = null;
        private ReservationBll reservationBll = null; 
        
        [TestInitialize]
        public void Init()
        {
            commonBll = new CommonBll();

            leadBll = new LeadBll();
            LeadDal leadDal = new LeadDal();
            //leadDal.log = new 
            leadDal.dapperHelper = new DapperHelper();
            leadBll.leadDal = leadDal;
            CommonWcf commonWcf = new CommonWcf();
            commonWcf.xrmService = new XrmService();
            leadBll.commonWcf = commonWcf;
            commonBll.leadBll = leadBll;

            screenCustomerBll = new ScreenCustomerBll();
            //  CommonWcf commonWcf1 = new CommonWcf();
            //commonWcf1.xrmService = new XrmService();
            ScreenCustomerDal screencustomerDal = new ScreenCustomerDal();
            screencustomerDal.dapperHelper = new DapperHelper();
            ResResult resResult = new ResResult();
            screenCustomerBll.resResult = resResult;
            screenCustomerBll.commonWcf = commonWcf;
            screenCustomerBll.screencustomerDal = screencustomerDal;
            commonBll.screenCustomerBll = screenCustomerBll;

            commonBll.sequenceBll = new SequenceBll();
            commonBll.sequenceBll.sequenceDal = new SequenceDal();
            commonBll.sequenceBll.sequenceDal.dapperHelper = new DapperHelper();
            commonBll.commonWcf = new CommonWcf();

            screenResultBll = new ScreenResultBll();
            ResResult resResult1 = new ResResult();
            //CommonWcf commonWcf2 = new CommonWcf();
            //commonWcf2.xrmService = new XrmService();
            screenResultBll.resResult = resResult1;
            screenResultBll.commonWcf = commonWcf;
            commonBll.screenResultBll = screenResultBll;


            screenPropagandaBll = new ScreenPropagandaBll();
            //CommonWcf commonWcf3 = new CommonWcf();
            //commonWcf3.xrmService = new XrmService();
            screenPropagandaBll.commonWcf = commonWcf;
            commonBll.screenPropagandaBll = screenPropagandaBll;
            screenPropagandaBll.resResult = new ResResult();


            reservationBll = new ReservationBll();
            reservationBll.commonWcf = commonWcf;
            commonBll.reservationBll = reservationBll;



        }

        [TestMethod()]
        public void CreateSQSCUT()
        {
            SCOBJ sCOBJ = new SCOBJ();
            LeadInfo lead = new LeadInfo();
            ScreenPropaganda propaganda = new ScreenPropaganda();
            Reservation reservation = new Reservation();
            ScreenCustomer customer = new ScreenCustomer();
            List<ScreenResult> createResults = new List<ScreenResult>();
            ScreenResult screenResult = new ScreenResult();
            Guid scid = new Guid("7c6d4ced-36f6-e811-8103-fb5493c0aa7a");
            Guid ownerid = new Guid("0268B153-33AA-E411-80B6-00155D94EE04");
            //潜客信息
            lead.userid = ownerid;
            lead.lastname = "妈耶";
            lead.new_gender = 1;
            lead.new_age = 20;
            lead.new_insurancetype = null;
           // lead.new_screen = scid;
            lead.address1_telephone1 = "18666537994";
            lead.new_phone = "18666537994";
            lead.new_mobile = "88888888";
            lead.telephone2 = "88888888";
            lead.address1_telephone2 = "88888888";
            lead.new_disease = 1;
            lead.address1_name = "长沙市天心区春田花花幼儿园";
            lead.new_citizenid = "";
            lead.new_insuranceid = "";
            lead.description = "无话可说";
            lead.new_patientsource = 3;
            lead.new_inputingtime = DateTime.Now;
            lead.new_datasource = 9;
            lead.new_reservation = false;

            //筛查客户
            //new_customerid
            customer.new_scid = scid;
           // customer.new_scstate = 0;
            //customer.new_reportcount = 30;
            customer.new_screenteamid = new Guid("93f5323a-4c2f-e511-80c0-00155d94ee04");
            customer.new_scitemid = Guid.Empty;
            //customer.new_scnum = "ak123456";
            //customer.ownerid = ownerid;

            //筛查\宣教活动
            screenResult.new_scid = scid;
            screenResult.new_categoryid = "";
            screenResult.new_itemid = "";
            screenResult.new_contentid = "";
            //screenResult.new_customerid = Guid.Empty;
           // screenResult.new_result = "";
            screenResult.new_doctorid = ownerid;
            screenResult.OwnerId = ownerid;

            //宣教
            propaganda.new_name = "测试20190802";
            //propaganda.new_lead = 
            propaganda.new_gender = 1;
            propaganda.new_age = 20;
            propaganda.new_mobile = "";
            propaganda.new_tel = "";
            propaganda.new_healthinsuranceplace = 2;
            propaganda.new_isorder = false;
            propaganda.new_isfollowself = 0;
            propaganda.new_followdoctor = ownerid;
            propaganda.new_countteardrop = 0;
            propaganda.new_doctor = ownerid;
            propaganda.new_screen = scid;
 //           propaganda.ownerid = ownerid;

            //预约


            sCOBJ.lead = lead;
            sCOBJ.propaganda = propaganda;
            sCOBJ.reservation = reservation;
            sCOBJ.customer = customer;
            createResults.Add(screenResult);
            sCOBJ.CreateResults = createResults;

           string jsonstr =  Newtonsoft.Json.JsonConvert.SerializeObject(sCOBJ);
            Console.WriteLine(jsonstr);

           // commonBll.CreateSQSC(sCOBJ);
        }


        [TestMethod()]
        public void CreateSQXYUT()
        {
            SCOBJ sCOBJ = new SCOBJ();
            LeadInfo lead = new LeadInfo();
            Screen screen = new Screen();
            ScreenPropaganda propaganda = new ScreenPropaganda();
            Reservation reservation = new Reservation();
            ScreenCustomer customer = new ScreenCustomer();
            List<ScreenResult> createResults = new List<ScreenResult>();
            ScreenResult screenResult = new ScreenResult();
            Guid scid = new Guid("32232D9B-081F-E511-80BE-00155D94EE04");
            Guid ownerid = new Guid("0268B153-33AA-E411-80B6-00155D94EE04");
            //潜客信息
            lead.leadid = Guid.Parse("8EF85A78-441A-E511-80BE-00155D94EE04");
            lead.userid = ownerid;
            lead.lastname = "20190805测试";
            lead.new_gender = 1;
            lead.new_age = 20;
            lead.new_insurancetype = null;
            // lead.new_screen = scid;
            lead.address1_telephone1 = "13789230456";
            lead.new_phone = "13789230456";
            lead.new_mobile = "67667656";
            lead.telephone2 = "543536554";
            lead.address1_telephone2 = "67667656";
            lead.new_disease = 1;
            lead.address1_name = "长沙市天心区春田花花幼儿园";
            lead.new_citizenid = "";
            lead.new_insuranceid = "";
            lead.description = "无话可说";
            lead.new_patientsource = 3;
            lead.new_inputingtime = DateTime.Now;
            lead.new_datasource = 9;
            lead.new_reservation = false;

            screen.new_screenId = scid;
            screen.new_schoolId = Guid.Parse("66AAFDDF-3AC8-E411-80B6-00155D94EE04");
            screen.new_screenteamId = Guid.Parse("E35936D9-492F-E511-80C0-00155D94EE04");
            screen.new_new_screenitem = Guid.Parse("4CDBE820-CC40-E511-80C1-00155D94EE04");
            sCOBJ.screen = screen;

            //筛查客户
            //new_customerid
            customer.new_scid = scid;
            // customer.new_scstate = 0;
            //customer.new_reportcount = 30;
            customer.new_screenteamid = new Guid("E35936D9-492F-E511-80C0-00155D94EE04");
            customer.new_scitemid = Guid.Empty;
            //customer.new_scnum = "ak123456";
            //customer.ownerid = ownerid;

            //筛查\宣教活动
            screenResult.new_scid = scid;
            screenResult.new_categoryid = "LB0001";
            screenResult.new_itemid = "XM0002";
            screenResult.new_contentid = "NR0004";
            //screenResult.new_customerid = Guid.Empty;
            // screenResult.new_result = "";
            screenResult.new_doctorid = ownerid;
            screenResult.OwnerId = ownerid;

            //宣教
            propaganda.new_name = "测试20190802";
            //propaganda.new_lead = 
            propaganda.new_gender = 1;
            propaganda.new_age = 20;
            propaganda.new_mobile = "";
            propaganda.new_tel = "";
            propaganda.new_healthinsuranceplace = 2;
            propaganda.new_isorder = false;
            propaganda.new_isfollowself = 0;
            propaganda.new_followdoctor = ownerid;
            propaganda.new_countteardrop = 0;
            propaganda.new_doctor = ownerid;
            propaganda.new_screen = scid;
            //           propaganda.ownerid = ownerid;

            //预约




            sCOBJ.lead = lead;
            sCOBJ.propaganda = propaganda;
            sCOBJ.reservation = reservation;
            sCOBJ.customer = customer;
            createResults.Add(screenResult);
            sCOBJ.CreateResults = createResults;

            string jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(sCOBJ);
            Console.WriteLine(jsonstr);

            commonBll.CreateXYSC(sCOBJ);
        }

        [TestMethod()]
        public void UpdateSQXYUT()
        {
            SCOBJ sCOBJ = new SCOBJ();
            LeadInfo lead = new LeadInfo();
            Screen screen = new Screen();
            ScreenPropaganda propaganda = new ScreenPropaganda();
            Reservation reservation = new Reservation();
            ScreenCustomer customer = new ScreenCustomer();
            List<ScreenResult> createResults = new List<ScreenResult>();
            ScreenResult screenResult = new ScreenResult();
            Guid scid = new Guid("32232D9B-081F-E511-80BE-00155D94EE04");
            Guid ownerid = new Guid("0268B153-33AA-E411-80B6-00155D94EE04");
            //潜客信息
            lead.leadid = Guid.Parse("8EF85A78-441A-E511-80BE-00155D94EE04");
            lead.userid = ownerid;
            lead.lastname = "20190805测试";
            lead.new_gender = 1;
            lead.new_age = 20;
            lead.new_insurancetype = null;
            // lead.new_screen = scid;
            lead.address1_telephone1 = "13789230456";
            lead.new_phone = "13789230456";
            lead.new_mobile = "67667656";
            lead.telephone2 = "543536554";
            lead.address1_telephone2 = "67667656";
            lead.new_disease = 1;
            lead.address1_name = "长沙市天心区春田花花幼儿园";
            lead.new_citizenid = "";
            lead.new_insuranceid = "";
            lead.description = "无话可说";
            lead.new_patientsource = 3;
            lead.new_inputingtime = DateTime.Now;
            lead.new_datasource = 9;
            lead.new_reservation = false;

            screen.new_screenId = scid;
            screen.new_schoolId = Guid.Parse("66AAFDDF-3AC8-E411-80B6-00155D94EE04");
            screen.new_screenteamId = Guid.Parse("E35936D9-492F-E511-80C0-00155D94EE04");
            screen.new_new_screenitem = Guid.Parse("4CDBE820-CC40-E511-80C1-00155D94EE04");
            sCOBJ.screen = screen;

            //筛查客户
            //new_customerid
            customer.new_scid = scid;
            // customer.new_scstate = 0;
            //customer.new_reportcount = 30;
            customer.new_screenteamid = new Guid("E35936D9-492F-E511-80C0-00155D94EE04");
            customer.new_scitemid = Guid.Empty;
            //customer.new_scnum = "ak123456";
            //customer.ownerid = ownerid;

            //筛查\宣教活动
            screenResult.new_scid = scid;
            screenResult.new_categoryid = "LB0001";
            screenResult.new_itemid = "XM0002";
            screenResult.new_contentid = "NR0004";
            //screenResult.new_customerid = Guid.Empty;
            // screenResult.new_result = "";
            screenResult.new_doctorid = ownerid;
            screenResult.OwnerId = ownerid;

            //宣教
            propaganda.new_name = "测试20190802";
            //propaganda.new_lead = 
            propaganda.new_gender = 1;
            propaganda.new_age = 20;
            propaganda.new_mobile = "";
            propaganda.new_tel = "";
            propaganda.new_healthinsuranceplace = 2;
            propaganda.new_isorder = false;
            propaganda.new_isfollowself = 0;
            propaganda.new_followdoctor = ownerid;
            propaganda.new_countteardrop = 0;
            propaganda.new_doctor = ownerid;
            propaganda.new_screen = scid;
            //           propaganda.ownerid = ownerid;

            //预约

            sCOBJ.lead = lead;
            sCOBJ.propaganda = propaganda;
            sCOBJ.reservation = reservation;
            sCOBJ.customer = customer;
            createResults.Add(screenResult);
            sCOBJ.CreateResults = createResults;

            string jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(sCOBJ);
            Console.WriteLine(jsonstr);

            commonBll.UpdateXYSC(sCOBJ);
        }
    }
}